Skip to content

Conversation

@bkhouri
Copy link
Contributor

@bkhouri bkhouri commented Nov 19, 2025

Format the repository

@bkhouri bkhouri changed the title T/main/format repo and enforce formatting Format repo and enforce formatting in CI Nov 19, 2025
@bkhouri bkhouri marked this pull request as draft November 19, 2025 21:38
@bkhouri
Copy link
Contributor Author

bkhouri commented Nov 19, 2025

swift format does not trim empty lines :(

I created swiftlang/swift-format#1097 to track resolution

@bkhouri bkhouri force-pushed the t/main/format_repo_and_enforce_formatting branch from 2617aa7 to 2f8edab Compare November 19, 2025 21:44
@bkhouri bkhouri marked this pull request as ready for review November 19, 2025 22:50
@owenv
Copy link
Collaborator

owenv commented Nov 20, 2025

I'm somewhat hesitant to enforce formatting in CI since support in editors for running swift-format-on-save is spotty and it can be pretty frustrating to need to re-run CI when everything passed except the formatting enforcement

@jakepetroules
Copy link
Collaborator

jakepetroules commented Nov 20, 2025

I'm fairly neutral on it, but wouldn't mind formatting being enforced.

it can be pretty frustrating to need to re-run CI when everything passed except the formatting enforcement

It's possible there might be a way to configure swiftlang/github-workflows to make other jobs dependent on the formatting one, which would reduce that concern since you wouldn't waste resources or time waiting for the longer jobs to complete. EDIT: tried this in #937, it's straightforward.

@bkhouri
Copy link
Contributor Author

bkhouri commented Nov 20, 2025

Shall I incorporate #937 into this PR?

@bkhouri bkhouri force-pushed the t/main/format_repo_and_enforce_formatting branch from 2f8edab to cab13c9 Compare November 20, 2025 16:12
Update the GitHub workflows to enfore formatting, and include instructions
on how to configure `git blame` to ignore the formatting commit.
@bkhouri bkhouri force-pushed the t/main/format_repo_and_enforce_formatting branch from cab13c9 to 46294d1 Compare November 20, 2025 16:18
@bkhouri
Copy link
Contributor Author

bkhouri commented Nov 20, 2025

@swift-ci test

@bkhouri
Copy link
Contributor Author

bkhouri commented Nov 20, 2025

I worked around swiftlang/swift-format#1097 by updating the comment style. I also incorporated #937 in this change, which runs the Soundness and Space format Check builds before the others.

@bkhouri bkhouri enabled auto-merge November 20, 2025 16:21
@bkhouri
Copy link
Contributor Author

bkhouri commented Nov 20, 2025

@swift-ci test

@mhrawdon
Copy link
Contributor

I feel pretty strongly that we should not do this. I don't think issues with code formatting is a problem we have (or have ever had), it adds additional overhead to making changes (which are already pretty high-overhead), and it takes away the latitude to make different format choices if it improves readability.

We've discussed this several times over the last ten years and have always decided not to do it.

it can be pretty frustrating to need to re-run CI when everything passed except the formatting enforcement

I think if this ever has to be done, even for a fast-to-run CI job, then it's obstructing more than it's helping.

Please, let's not do this.

"-DCMAKE_Swift_FLAGS='\(sharedSwiftFlags.joined(separator: " "))'"
] + cMakeProjectArgs + extraCMakeArgs
let sharedCMakeArgs =
[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should make this change. The open bracket [ should be on the same line as the =, same as open curly braces for methods, etc.

If we do make this change, then I think the open bracket should be aligned with the l in let. The contents of the array should not be double-indented.

}
return result
}
func scan<S: Sequence, U>(_ seq: S, _ initial: U, _ combine: (U, S.Element) -> U) -> [U] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a function like this should be indents inside a Swift compilation condition. Functions should remain flush with other functions in the same notional scope.

I can see making an exception for compilation conditions which are inside procedural logic (such as in host() above) although I'm indifferent to it, but not for functions. If we can't have it both ways, then I think we should leave such indentation up to the author.

let (key, value) = $0.split("=")
return (key.trimmingCharacters(in: .whitespaces), value.trimmingCharacters(in: .whitespaces))
})
properties = Dictionary(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this sort of formatting decision should be left to the discretion of the author.

"FamilyIdentifier": .plString("android"),
"IsDeploymentPlatform": .plString("YES"),
])
(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this sort of formatting decision should be left to the discretion of the author.

In this case I prefer the old version.

try (max(deploymentTargetRange.min, abi.min_os_version)...deploymentTargetRange.max).map { deploymentTarget in
var triple = abi.llvm_triple
triple.vendor = "unknown" // Android NDK uses "none", Swift SDKs use "unknown"
triple.vendor = "unknown" // Android NDK uses "none", Swift SDKs use "unknown"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I think this change is fine, I also think this is a change that should never cause CI to fail.

If this is the sort of thing we want to enforce, then we should run the formatter monthly or something to fix up any cases that have been introduced. But I also don't think this is really a problem that deserves that amount of effort.

@matthewseaman
Copy link
Contributor

I would also vote against doing this for the reasons @mhrawdon outlined. I've even removed a linter from a different project because it was drawing too much attention to stylistic issues that were not hurting anything and distracting from the real issues that the Swift compiler emits.

Some issues are purely matters of opinion (like whether a space should be before a colon) and do not hurt readability either way. Other stylistic matters could have a pretty reasonable general rule but then there are always many exceptions to that rule where the exceptions actually produce better readability in that specific instance. Other times the linter takes the absolutist position that a certain language feature should always be avoided even though every tool in Swift has a purpose.
Then finally there are a handful of cases that really are pretty universal and could be handy to enforce, but those are also the types of things that most engineers are going to fix up themselves without needing it to be enforced by CI or auto-applied to all code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants